#include "stdafx.h"
#include "BaseToolsClass.h"

static XLLRTGlobalAPI  luaBaseComClassMemberFuns[]=
{
	{"AttachEventListener",CBaseToolsClass::AttachEventListener},
	{"GetDeviceCaps",CBaseToolsClass::GetDeviceCaps},
	{"__gc",CBaseToolsClass::DeleteSelf},
	{NULL,NULL}
};

int CBaseToolsClass::GetDeviceCaps(lua_State* luaState)
{
	int nTop=lua_gettop(luaState);

	BOOL bFull=lua_toboolean(luaState,nTop);
	int width=0,height=0;
	if(bFull)
	{
		width =GetSystemMetrics(SM_CXSCREEN);
		height=GetSystemMetrics(SM_CYSCREEN);
	}
	else
	{
		width =GetSystemMetrics(SM_CXFULLSCREEN);
		height=GetSystemMetrics(SM_CYFULLSCREEN);
	}
	lua_pushinteger(luaState,width);
	lua_pushinteger(luaState,height);
	
	int nRet=XLLRT_LuaCall(luaState,2,1,L"CBaseToolsClass::GetDeviceCaps");
	lua_settop(luaState,nTop);

	return nRet;
}

int CBaseToolsClass::RegisterClass(XL_LRT_ENV_HANDLE hEnv)
{
	if(hEnv==NULL)
		return 0;
	return XLLRT_RegisterClass(hEnv,BASETOOLSCLASS_CLASS,luaBaseComClassMemberFuns,NULL,0);
}

int CBaseToolsClass::AttachEventListener(lua_State* luaState)
{
	return 1;
}

int CBaseToolsClass::DeleteSelf(lua_State* luaState)
{
	return 1;
}

int CBaseToolsClass::ListenerCallBack(DWORD dwParam1,DWORD dwParam2,int nIndex)
{
	return 1;
}



//--------------------------//
CBaseToolsClassFactory* CBaseToolsClassFactory::m_pObj=NULL;

static XLLRTGlobalAPI  luaBaseComClassFactoryMemberFuns[]=
{
	{"CreateInstance",CBaseToolsClassFactory::CreateInstance},
	{NULL,NULL}
};

CBaseToolsClassFactory* CBaseToolsClassFactory::Instance()
{
	if(m_pObj==NULL)
		m_pObj=new CBaseToolsClassFactory();
	return m_pObj;
}

int CBaseToolsClassFactory::CreateInstance(lua_State* luaState)
{
	CBaseToolsClass* pBaseComClass=new CBaseToolsClass();
	XLLRT_PushXLObject(luaState,BASETOOLSCLASS_CLASS,pBaseComClass);
	return 1;
}

void CBaseToolsClassFactory::RegisterObj(XL_LRT_ENV_HANDLE hEnv)
{
	if(hEnv==NULL)
		return;
	XLLRTObject lrtObj;
	lrtObj.ClassName=BASETOOLSCLASS_FACTORY_CLASS;
	lrtObj.MemberFunctions=luaBaseComClassFactoryMemberFuns;
	lrtObj.ObjName=BASETOOLSCLASS_FACTORY_OBJ;
	lrtObj.userData=NULL;
	lrtObj.pfnGetObject=(fnGetObject)CBaseToolsClassFactory::Instance;

	XLLRT_RegisterGlobalObj(hEnv,lrtObj);
}